﻿#include<iostream>
#include<vector>

void printVector(std::vector<int>& v)
{
	for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it)
	{
		std::cout << *it << ' ';
	}
	std::cout << '\n';
}



void test01()
{
	std::vector<int> v1;
	for (int i = 0; i < 10; ++i)
	{
		v1.push_back(i);
	}
	printVector(v1);

	std::vector<int> v2;
	for (int i = 9; i >= 0; --i)
	{
		v2.push_back(i);
	}
	printVector(v2);

	std::cout << "交换后：" << '\n';
	v2.swap(v1);
	printVector(v1);
	printVector(v2);
}

void test02()
{
	std::vector<int> v;
	for (int i = 0; i < 10000; ++i)
	{
		v.push_back(i);
	}
	std::cout << "v的容量为：" << v.capacity() << '\n';
	std::cout << "v的大小为：" << v.size() << '\n';

	v.resize(6);
	std::cout << "重新设置大小：" << '\n';
	std::cout << "v的容量为：" << v.capacity() << '\n';
	std::cout << "v的大小为：" << v.size() << '\n';

	std::vector<int>(v).swap(v);
	std::cout << "交换后：" << '\n';
	std::cout << "v的容量为：" << v.capacity() << '\n';
	std::cout << "v的大小为：" << v.size() << '\n';
}


int main()
{
	test01();
	std::cout << "-------------------" << '\n';
	test02();


	return 0;
}